import QtQuick 2.12
import QtQml.Models 2.12

Item {
    id: root
    height: notificationList.height

    property var groupData: null
    property int groupIndex: -1

    Component.onCompleted: {
        notificationModel.model = groupModel;
        notificationModel.rootIndex = notificationModel.modelIndex(root.groupIndex);
    }

    DelegateModel {
        id: notificationModel
        property string name: groupData.groupName

        delegate: Rectangle {
            height: 30
            width: ListView.view.width
            color: "pink"

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    sourceModel.execAction(model.id);
                }
            }

            Row {
                anchors.fill: parent
                spacing: 10
                Text {
                    text: model.id
                }
                Text {
                    text: model.index
                }
                Text {
                    text: model.appName
                }
                Text {
                    text: model.body
                }
            }
        }
    }

    ListView {
        id: notificationList
        width: parent.width
        height: contentHeight
        spacing: 5

        model: notificationModel
        header: Component {
            Rectangle {
                width: parent.width
                height: 30
                color: "lightblue"
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        var modelIndex = notificationList.model.rootIndex;
                        console.log("group index:", groupIndex, modelIndex);
                    }
                }
                Row {
                    anchors.fill: parent
                    spacing: 10
                    Text {
                        text: "index: " + groupData.index
                    }
                    Text {
                        text: "group name: " + groupData.groupName
                    }
                    Text {
                        text: "group count: " + groupData.groupCount
                    }
                }
            }
        }
    }
}
